#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MKGeometry.h>

#import "FWCommon.h"

#import "FWMapAnnotation.h"


@implementation FWMapAnnotation

@synthesize coordinate, title, subtitle;


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (id)initWithTitle:(NSString *)ttl subtitle:(NSString *)sttl andCoordinate:(CLLocationCoordinate2D)c2d
{
    if ((self = [super init])) {
        coordinate = c2d;
        title = [ttl copy];
        subtitle = [sttl copy];
    }
    
    return self;
}

- (void)dealloc
{
    [title release];
    title = nil;
    [subtitle release];
    subtitle = nil;
    
    [super dealloc];
}


// ******************************************************************************************
#pragma mark -
#pragma mark Ignore KVO registration calls

// For some reason KVO registration causes the mapview to crash when annotations are added
// from two different plugins. Likely it's because the "coordinates" property isn't coded
// to be fully KVO compliant but I don't know what's wrong. Ignoring KVO observer registrations
// appears to work around the problem.

- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
{
    // Ignore
    DebugLog(@"Register observer; obs = %@; keyPath = %@; options = %i; context = %@", observer, keyPath, options, context);
}

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(void *)context
{
    // Ignore
    DebugLog(@"Remove observer; obs = %@; keyPath = %@; context = %@", observer, keyPath, context);
}

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
{
    // Ignore
    DebugLog(@"Remove observer; obs = %@; keyPath = %@", observer, keyPath);
}

@end
